package com.cyx.controller;

import com.cyx.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
@RequestMapping("/user")
public class UserController {
    //http://localhost:8080/user/get3?name=caoyx&age=33
    @RequestMapping("/get")
    public String getUser(String name,Integer age, Model model){
        model.addAttribute("userName",name);
        model.addAttribute("age",age);
        return "user";
    }

    //URL 请求参数名与参名不一样，可以通过RequestParam指定  http://localhost:8080/user/get3?name=caoyx&age=33
    @RequestMapping("/get2")
    public  String getUser2(@RequestParam("name") String userName, Integer age, Model model){
        model.addAttribute("userName",userName+"2");
        model.addAttribute("age",age);
        return "user";
    }

    //处理函数参数为对象 http://localhost:8080/user/get3?userName=caoyx&age=33
    @RequestMapping("/get3")
    public String getUser3(User user,Model model){
        System.out.println(user);
        //model.addAttribute(user);
        model.addAttribute("userName",user.getUserName()+"3");
        model.addAttribute("age",user.getAge());
        return "user";
    }
}
